<%@page import="com.antexpress.common.Const"%>
<%@page import="com.antexpress.pojo.Employee"%>
<%@page import="com.antexpress.bean.Authentication"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Upload File</title>
        <link rel="shortcut icon" href="static/img/ant-logo.png">
        <link href="static/css/style.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/normalize.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/default.css" rel="stylesheet" type="text/css"/>
        <link href="static/dist/css/jquery.secretnav.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/demo.css" rel="stylesheet" type="text/css"/>
        <link href="static/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css"/>
    </head>
    <body id="bk">
        <%
            if(!Authentication.isLogin(session)) {
                response.sendRedirect("index.jsp");
                return;
            }
            Employee user = (Employee)session.getAttribute(Const.CURRENT_USER);
        %>
        <div class="sn-outer-wrapper sn-moveleft modalview">
            <div class="sn-content-wrapper transform" style="cursor: default;">
                <div id="content" style="top: 0px;">
                    <jsp:include page="ui/header.jsp"/>
                    <div class="container-nav">
                        <div class="container">
                            <button class="open btn btn-default bt-open" title="Menu"><i class="fa fa-bars" aria-hidden="true"></i></button>
                            <%
                                if (Authentication.isExpressLogisticsManager(user)) {
                                    out.println("<a href='courier.jsp' class='content-nav-bt'>Courier Management</a>");
                                    out.println("<a href='parse_district.jsp' class='content-nav-bt'>Area Infomation Upload</a>");
                                }
                            %>
                        </div>
                    </div>
                    <div class="container" style="color:#000;padding-top: 20px;text-align: left;">
                        <h1 class="heading"><i class="fa fa-users" aria-hidden="true"></i> Area File Upload</h1>
                        <div class="content-center">
                            <form id="uploadForm" onsubmit="return false;" enctype="multipart/form-data">
                                Select File:&nbsp;<input id="file" type="file" name="file"/><br/><br/>
                                <div style="font-size: 10pt;color: red;">* If the areas are already existed in the database, these area data cannot be upload again. Please choose carefully!</div>
                                <br/>
                                <button class="btn btn-primary" id="upload">Upload</button>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="sn-nav-wrapper">
                    <nav id="nav" class="sn-nav left vertical">
                        <jsp:include page="ui/nav.jsp"/>
                    </nav>
                </div>
            </div>
        </div>
        <script src="static/js/modernizr.custom.25376.js" type="text/javascript"></script>
        <script src="static/js/jquery.js" type="text/javascript"></script>
        <script src="static/js/common-script.js" type="text/javascript"></script>
        <script src="static/dist/js/jquery.secretnav.js" type="text/javascript"></script>
        <script src="static/js/jquery.edbox.js" type="text/javascript"></script>
        <script src="static/js/center-loader.js" type="text/javascript"></script>
        <script type="text/javascript">  
            $(function(){
                menu();
            });
            $("#upload").click(function(){
                var formData = new FormData($('#uploadForm')[0]);  
                $('#bk').loader('show','<i class="fa fa-2x fa-spinner fa-pulse"></i>');
                $.ajax({  
                    type: 'post',  
                    url: "${pageContext.request.contextPath}/area/upload_file.do",  
                    data: formData,
                    contentType:false,
                    processData: false,
                success:function (data) {
                    $('#bk').loader('hide');
                    alert("上传成功");  
                },
                error:function () {  
                    $('#bk').loader('hide');
                    alert("上传失败");  
                }
                });  
            });
    </script>
    </body>
    
</html>
